package com.fyzk.activity.lottery.jc.football;


import com.fyzk.activity.lottery.jc.football.adapter.JCZQ_BQC_ZhiFuAdapter;
import com.fyzk.activity.lottery.jc.football.guoguan.JC_GuoGuanDialog;
import com.fyzk.activity.lottery.jc.football.guoguan.JC_GuoGuanInfor;
import com.fyzk.activity.lottery.zc.tz_dialog.ZCBF_infor;
import com.fyzk.activity.zhifu.SportsFootballPayActivity;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class JCZQ_BQC_ZhiFuActivity extends SportsFootballPayActivity {

    @Override
    protected void onResume() {
        super.onResume();
        buyType.setText("竞彩足球-半全场");
    }

    @Override
    protected void clear() {
        // TODO Auto-generated method stub
        super.clear();
        for (int i = 0; i < infos.size(); i++) {
            JCInfo info = infos.get(i);
            if (info.getOnclikNum() > 0) {
                info.setOnclikNum(0);
                Set<String> keys = info.btnHGPojo.keySet();
                for (String key : keys) {
                    info.btnHGPojo.get(key).isSel = false;
                }
            }
            List<ZCBF_infor> touZhu = info.getTouZhuInfor();
            for (int j = 0; j < touZhu.size(); j++) {
                touZhu.get(j).setSelect(false);
            }
            info.setResult("");
        }
        adapter.setInfors(infos, isDanguan);
        adapter.notifyDataSetChanged();
    }

    @Override
    protected void initAdapter() {
        adapter = new JCZQ_BQC_ZhiFuAdapter(this, isDanguan, infos, handler, this);
        listView.setAdapter(adapter);
    }


    /**
     * 获取投注内容   301012001-20140304002(10)|20140304003(13)^
     *
     * @param infos
     */
    public String getContent(List<JCInfo> infos, boolean isdanguan) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(JC_GuoGuanDialog.result, isdanguan);
        String content = "";

        for (int i = 0; i < chuans.size(); i++) {
            content += lotteryId + "" + wanFa + chuans.get(i) + "-";

            String n = "";
            String danCodes = "";
            for (int j = 0; j < infos.size(); j++) {
                JCInfo info = infos.get(j);
                StringBuffer danChang = new StringBuffer();
                if (info.getOnclikNum() > 0) {
                    danChang.append(info.getMatchNum());
                    danChang.append("(");
                    Set<String> keys = info.btnHGPojo.keySet();
                    Iterator<String> keyIterator = keys.iterator();
                    while (keyIterator.hasNext()) {
                        String key = keyIterator.next();
                        JCInfo.SPInfo spInfo = info.btnHGPojo.get(key);
                        if (spInfo.isSel) {
                            danChang.append(spInfo.codeValue);
                            danChang.append(",");
                        }
                    }

                    danChang.deleteCharAt(danChang.length() - 1);
                    danChang.append(")");
                    if (!danChang.equals("")) {
                        if (info.isDan()) {
                            danCodes += danChang + "|";
                        } else {
                            n += danChang + "|";
                        }
                    }
                }

            }
            if (!danCodes.equals("")) {
                danCodes = danCodes.substring(0, danCodes.length() - 1);
                danCodes += "#";
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }

            content += danCodes + n + "!";
        }

        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }

        return content;
    }

    @Override
    protected int getMaxGuoGuan() {
        // TODO Auto-generated method stub
        return 4;
    }

    @Override
    public void open(JCInfo info) {

    }
}
